Skip to content

feat: add pagination to GET /api/streams/:id/history - #900

Open
ZuLu0890 wants to merge 1 commit into
ritik4ever:mainfrom
ZuLu0890:feat/history-pagination
Open

feat: add pagination to GET /api/streams/:id/history#900
ZuLu0890 wants to merge 1 commit into
ritik4ever:mainfrom
ZuLu0890:feat/history-pagination

Conversation

@ZuLu0890

Copy link
Copy Markdown

Summary

Adds pagination to GET /api/streams/:id/history as described in #726. The endpoint now accepts page and limit query parameters (with a hard cap of 100), returns events sorted ascending by timestamp (oldest first), and responds with { data, total, page, limit }. Invalid parameters return a 400 VALIDATION_ERROR instead of being silently clamped.

Closes #726

Changes

Backend (backend/src/index.ts)

  • Parse & validate query params via the shared Zod listEventsQuerySchema, matching the /api/events and /api/metrics/history patterns (coerce to int, page >= 1, 1 <= limit <= 100400 with VALIDATION_ERROR on failure).
  • Default limit is now 50 (was a clamped pageSize default of 20).
  • History is served oldest-first (getStreamHistory(..., 'asc')).
  • Response is now { data, total, page, limit }; the previous pageSize/hasMore fields are removed.
  • pageSize remains a supported alias for limit for backwards compatibility.

Docs

  • backend/src/swagger.ts: documented the page/limit query params, the 400 response, and the total/page/limit fields in the 200 schema.
  • backend/TESTING.md: updated the manual test checklist.

Tests (backend/src/integration.test.ts)

  • Updated existing pagination tests to the new response shape (limit, no hasMore) and ascending order.
  • Added coverage for:
    • pagination correctness on a stream with 500+ events (disjoint slices, correct last-page remainder, ascending order);
    • 400 when limit exceeds 100;
    • 400 for invalid page/limit (zero, negative, non-integer);
    • default limit of 50;
    • pageSize alias.

Necessary build fix (backend/src/services/streamStore.ts)

  • Removed two stray lines in createStream (const built = await rpcServer.prepareTransaction() left over from the Soroban wiring merge (feat(backend): wire Soroban create_stream contract call with simulati… #650) that produced a SyntaxError, preventing the module — and therefore the whole backend and its test suite — from loading. Without this the endpoint cannot even be tested. Minimal, behavior-preserving.

Acceptance criteria

  • ✅ Pagination correct for streams with 500+ events — covered by the new integration test.
  • ✅ Response time < 150ms — page queries use indexed LIMIT/OFFSET against stream_events (~1–10ms in test logs).
  • ✅ Invalid params return 400 — covered by new tests.

Verification

  • npx vitest run src/integration.test.ts — pagination/history tests pass.
  • npx eslint on changed files — clean.
  • ⚠️ Note: main currently has pre-existing breakage unrelated to this PR (other integration tests and the full tsc typecheck fail due to missing db.ts exports like getAllowedAssets/searchStreamsFts, Soroban claimable/reconcile wiring, and several test files). That is out of scope and intentionally left for separate follow-ups; this PR is scoped to the pagination feature.

Add page/limit query params (max 100) to the stream history endpoint,
defaulting to limit 50 and returning events sorted ascending by
timestamp. The response now returns {data, total, page, limit} and
invalid params (non-integer, out-of-range, >100 limit) return 400 via
the shared Zod validation schema. pageSize is kept as a supported alias
for backwards compatibility.

Also fixes a pre-existing syntax error in streamStore#createStream
introduced by the Soroban wiring merge that prevented the module (and
the whole app/test suite) from parsing.

Tests extend the history integration coverage for the new spec,
including pagination correctness across 500+ events and 400 on invalid
params. Swagger spec and TESTING.md updated to document the params.

Closes ritik4ever#726

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@ZuLu0890 is attempting to deploy a commit to the ritik4ever's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@ZuLu0890 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a4693dd-1e56-4c7a-81e5-b4a875d213cc


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add pagination to GET /api/streams/:id/history

1 participant